package com.zs.grain.ui

import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Route
import com.jeremyliao.liveeventbus.LiveEventBus
import com.zs.grain.*
import com.zs.grain.databinding.FragmentWaitingBinding
import com.xnkj1688.semplibrary.mvvm.*
import com.zs.grain.tool.clockManage.LocalDataBase

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 */
@Route(path = ARouterPath.WaitingFragment)
class WaitingFragment : BaseMvvmFragment<FragmentWaitingBinding, WaitingViewModel>() {
    override val layoutId = R.layout.fragment_waiting

    override fun initCreate() {
        LiveEventBus.get("Waiting", Long::class.java).observe(this, Observer {
            mViewModel.init(it)
        })
    }

    override fun initViewModel(binding: FragmentWaitingBinding) {
        binding.vm = this.mViewModel
        binding.view = this
    }

    override fun initArguments() {
        var orderId = this.arguments?.getLong("OrderId")
        if (orderId != null) mViewModel.init(orderId)
    }

    override fun initAction() {
        LiveEventBus.get("DeviceService.Finish", Boolean::class.java)
            .observe(this, Observer {
                mViewModel.mDataService.insertLog("DeviceService-->DeviceService.Finish")
                mViewModel.onTaking()
            })
//        LiveEventBus.get().with("DeviceService.Error", String::class.java).observe(this, Observer {
//            mViewModel.onError(it)
//        })
    }

    override fun onPause() {
        super.onPause()
        mViewModel.stopProgressTimer()
        this.mViewModel.mSoundService.stopSound2()
    }

    override fun onDetach() {
        super.onDetach()
    }
}
